package a2023.a1010;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * @author lenovo
 * @date 2023/10/10
 */
public class a {
    public static void main(String[] args) {
        System.out.println(sumDistance(
                new int[]{-10, -13, 10, 14, 11},
                "LRLLR",
                2));
    }

    static final int MOD = 1000000007;

    public static int sumDistance(int[] nums, String s, int d) {
        int length = nums.length;
        long[] pos = new long[length];
        for (int i = 0; i < length; i++) {
            char c = s.charAt(i);
            if (c == 'L') {
                pos[i]=((long) nums[i] - d);
            } else {
                pos[i]=((long) nums[i] + d);
            }
        }
        Arrays.sort(pos);
        long num = 0;
        for (int i = 1; i < length; i++) {
            num += 1L * (pos[i] - pos[i - 1]) * i % MOD * (length - i) % MOD;
            num %= MOD;
        }
        return (int) num;
    }
}
